package com.ywq.app.dao.impl;

import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ywq.app.dao.AuxIdentifierDao;
import com.ywq.app.domain.AuxIdentifier;
import com.ywq.common.exception.AppBusinessException;


public class AuxIdentifierDaoImpl extends SqlSessionDaoSupport implements
		AuxIdentifierDao {

	private final static Logger logger = LoggerFactory
			.getLogger(AuxIdentifierDaoImpl.class);

	@Override
	public AuxIdentifier get(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return (AuxIdentifier) getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.AuxIdentifierMapper.getByName",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("query database failure.", e);
			}
			throw new AppBusinessException("query database failure.", e);
		}
	}

	@Override
	public void update(AuxIdentifier auxIdentifier) throws AppBusinessException {
		try {
			getSqlSession()
					.update("com.ywq.app.persistence.AuxIdentifierMapper.update",
							auxIdentifier);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("update database failure.", e);
			}
			throw new AppBusinessException("update database failure.", e);
		}
	}

	@Override
	public void insert(AuxIdentifier auxIdentifier) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.AuxIdentifierMapper.insert",
							auxIdentifier);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertAuxIdentifier database failure.", e);
			}
			throw new AppBusinessException(
					"insertAuxIdentifier database failure.", e);
		}
	}

}
